CheckPipelineMat.m 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. %=============================================================%
  2. % Checks .mat files for [MEG]PLS without having to load them. %
  3. % Similar to LoadFTmat except the file is NOT loaded. % %
  4. % If any errors are detected, they will be added to ErrLog. %
  5. % %
  6. % Note: This is for cases where "cfg.inputfile" is used. %
  7. % Allows files to be checked before being specified in cfg. %
  8. % Last modified: Sept. 7, 2014 %
  9. %=============================================================%
  10. % Copyright (C) 2013-2014, Michael J. Cheung
  11. %
  12. % This file is a part of the MEG & PLS Pipeline (MEGPLS). For more
  13. % details, see the documentation included with the software package.
  14. %
  15. % MEGPLS is free software: you can redistribute it and/or modify it under
  16. % the terms of the GNU General Public License version 2 as published by
  17. % the Free Software Foundation. This program is distributed in the hope
  18. % that it will be useful, but WITHOUT ANY WARRANTY; without even the
  19. % implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  20. % See the GNU General Public License for more details.
  21. %
  22. % You should have received a copy of the GNU General Public License along
  23. % with this program. If not, you can download the license here:
  24. % <http://www.gnu.org/licenses/old-licenses/gpl-2.0>.
  25. function Success = CheckPipelineMat(PipelineMat, RunSection)
  26. LoadErrLog = fopen(['ErrorLog_',RunSection,'.txt'], 'a');
  27. % Check if file exists:
  28. if ~exist(PipelineMat, 'file')
  29. fprintf(LoadErrLog, 'ERROR: Input file does not exist: \n %s \n\n', PipelineMat);
  30. disp('ERROR: Input .mat file is missing.')
  31. Success = 0;
  32. return;
  33. end
  34. % Make sure file is .mat:
  35. [~, ~, FileExt] = fileparts(PipelineMat);
  36. if ~strcmp(FileExt, '.mat')
  37. fprintf(LoadErrLog, 'ERROR: Input file is not a .mat: \n %s \n\n', PipelineMat);
  38. disp('ERROR: Failed to load. File is not a .mat.')
  39. Success = 0;
  40. return;
  41. end
  42. % Check if .mat is FT compatible:
  43. CheckVars = whos('-file', PipelineMat);
  44. if isempty(CheckVars)
  45. fprintf(LoadErrLog, 'ERROR: Input .mat file is empty: \n %s \n\n', PipelineMat);
  46. disp('ERROR: Input .mat file is empty.')
  47. Success = 0;
  48. return;
  49. end
  50. if length(CheckVars) > 1
  51. fprintf(LoadErrLog, ['ERROR: Loaded .mat is not FieldTrip compatible.'...
  52. '\nThe .mat file should only contain a single variable:'...
  53. '\n %s \n\n'], PipelineMat);
  54. disp('ERROR: Input .mat file is not FieldTrip compatible.')
  55. Success = 0;
  56. return;
  57. end
  58. Success = 1;
  59. fclose(LoadErrLog);